package com.wang.controller;

import com.wang.dao.AddUser;
import com.wang.dao.FindUser;
import com.wang.entity.User;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    private FindUser findUser = new FindUser();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = (String) req.getParameter("username");
        String password = (String) req.getParameter("password");
        User user = new User(null, username, password, 0);
        Boolean exist = findUser.findExist(user);
        System.out.println(exist);
        if(exist==true){
            System.out.println("登录成功");
            //用户存在,response重定向
            HttpSession session = req.getSession();
            ServletContext context = req.getServletContext();
            req.setAttribute("request","request");
            context.setAttribute("context","context");
            session.setAttribute("session",1);
            Cookie cookie = new Cookie("cookie","cookie");
            req.getRequestDispatcher("/WEB-INF/inner/bar.jsp").forward(req,resp);
        }
        else{
            System.out.println("登录失败");
        }
    }
}
